﻿using System;
using System.Web.Mvc;

namespace VisualAgile.Controllers
{
  public class ExtJsJsonReaderResult : JsonResult
  {
    public string RootName{get;set;}

    public ExtJsJsonReaderResult(string rootName, object orderDataObjects)
    {
      RootName = rootName;
      Data = orderDataObjects;
    }

    public override void ExecuteResult(ControllerContext context)
    {
      if (context == null)
        throw new ArgumentNullException("context");

      var response = context.HttpContext.Response;

      //response.ContentType = !string.IsNullOrEmpty(ContentType) ? 
      //                                                            ContentType : "application/json";

      //if (ContentEncoding != null)
      //  response.ContentEncoding = ContentEncoding;

      if (Data != null)
        response.Write(Data.ToExtJsJsonReader(RootName));
    }
  }
}